package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IFastTypeService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.FastTypeCreateValidate;
import com.mdd.admin.validate.FastTypeUpdateValidate;
import com.mdd.admin.validate.FastTypeSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.FastTypeListedVo;
import com.mdd.admin.vo.FastTypeDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/fast")
@Api(tags = "快递分类配置管理")
public class FastTypeController {

    @Resource
    IFastTypeService iFastTypeService;

    @GetMapping("/list")
    @ApiOperation(value="快递分类配置列表")
    public AjaxResult<PageResult<FastTypeListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated FastTypeSearchValidate searchValidate) {
        PageResult<FastTypeListedVo> list = iFastTypeService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="快递分类配置详情")
    public AjaxResult<FastTypeDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        FastTypeDetailVo detail = iFastTypeService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "快递分类配置新增")
    @PostMapping("/add")
    @ApiOperation(value="快递分类配置新增")
    public AjaxResult<Object> add(@Validated @RequestBody FastTypeCreateValidate createValidate) {
        iFastTypeService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "快递分类配置编辑")
    @PostMapping("/edit")
    @ApiOperation(value="快递分类配置编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody FastTypeUpdateValidate updateValidate) {
        iFastTypeService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "快递分类配置删除")
    @PostMapping("/del")
    @ApiOperation(value="快递分类配置删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iFastTypeService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
